home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / grid10.arc / GRID.C next >
C/C++ Source or Header  |  1991-03-10  |  5KB  |  160 lines

  1. // GRID.C  FreeWare by Scott R. Houck    10 March 91    MSC 6.00A
  2. //
  3. // This program prints a 25x80 grid with column and row numbers on an HP
  4. // laser printer.  It is intended for use in designing display screens.
  5. //
  6. // Usage:  GRID [?] [1] [7]
  7. //
  8. //    ?   Display usage and exit
  9. //    1   Rows and columns start with 1 (default is 0)
  10. //    7   Use 7 point (default is Line Printer 8.5 point)
  11. //
  12. // Complaints, suggestions and/or accolades can be forwarded to:
  13. //
  14. //     Scott R. Houck
  15. //     1880 Riggs Place, NW
  16. //     Washington, DC  20009
  17. //
  18. // If you like the program, send me a postcard!
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <stdarg.h>
  23.  
  24. #define VERSION       "1.0"
  25. #define ESC           "\033"
  26. #define NUMROWS       25      // Number of rows
  27. #define NUMCOLS       80      // Number of columns
  28. #define PHYSPGLENGTH  3300    // Landscape physical page length
  29. #define PHYSPGWIDTH   2550    // Landscape physical page width
  30. #define LEFTNONPRINT  60      // Nonprintable area on left
  31. #define TOPNONPRINT   50      // Nonprintable area on top
  32. #define FUDGE         115     // Seems to be needed for centering
  33. #define DOTSPERCOL    32      // Dots per column
  34. #define DOTSPERROW    64      // Dots per row
  35. #define BORDERWIDTH   4       // Border width for 75 dpi resolution
  36. #define GRIDWIDTH     (NUMCOLS * DOTSPERCOL + BORDERWIDTH)
  37. #define GRIDHEIGHT    (NUMROWS * DOTSPERROW + BORDERWIDTH)
  38. #define LEFTMARGIN    ((PHYSPGLENGTH - GRIDWIDTH)  / 2 - LEFTNONPRINT)
  39. #define TOPMARGIN     ((PHYSPGWIDTH  - GRIDHEIGHT) / 2 - TOPNONPRINT - FUDGE)
  40. #define RIGHTX        (GRIDWIDTH  + LEFTMARGIN - 1)
  41. #define BOTTOMY       (GRIDHEIGHT + TOPMARGIN  - BORDERWIDTH)
  42. #define LEFTX         (LEFTMARGIN - 1)
  43.  
  44. void Print(char *, ...);
  45.  
  46. main(int argc, char *argv[])
  47. {
  48.    int offset = 0, sevenpt = 0, adjust1 = 43, adjust2 = 46;
  49.    int i, row, column, xpos, remainder, quotient;
  50.  
  51.    fprintf(stderr, "GRID v" VERSION " by Scott R. Houck\n\n");
  52.  
  53.    while (--argc)
  54.       switch (argv[argc][0])
  55.          {
  56.          case '?':
  57.             fprintf(stderr,
  58.                "Usage:  GRID [?] [1] [7]\n\n"
  59.                "   ?   Display usage and exit\n"
  60.                "   1   Rows and columns start with 1 (default is 0)\n"
  61.                "   7   Use 7 point (default is Line Printer 8.5 point)\n");
  62.             exit(0);
  63.             break;
  64.  
  65.          case '1':
  66.             offset = 1;
  67.             break;
  68.  
  69.          case '7':
  70.             sevenpt = 1;
  71.             adjust1 = 37;
  72.             adjust2 = 42;
  73.             break;
  74.          }
  75.  
  76.    if (sevenpt)
  77.       printf("Using 7 point condensed font\n");
  78.    else
  79.       printf("Using 8.5 point Line Printer font\n");
  80.  
  81.    printf("Rows and columns start with %d\n", offset);
  82.  
  83.    // Reset the printer
  84.    Print(ESC "E");
  85.  
  86.    // Set landscape orientation
  87.    Print(ESC "&l1O");
  88.  
  89.    // Specify the raster graphics resolution (75 dpi)
  90.    Print(ESC "*t75R");
  91.  
  92.    printf("Printing row   ");
  93.    for (row = 0; row < NUMROWS; row++)
  94.       {
  95.       printf("\b\b%2d", row + offset);
  96.  
  97.       // Position the cursor
  98.       Print(ESC "*p%dx%dY", RIGHTX, TOPMARGIN + row * DOTSPERROW);
  99.  
  100.       // Specify the left raster graphics margin (current X position)
  101.       Print(ESC "*r1A");
  102.  
  103.       // Transfer the raster data
  104.       for (column = 0; column < NUMCOLS; column++)
  105.          {
  106.          Print(ESC "*b2W%c%c", 0xff, 0xff);     // Right border
  107.          for (i = 0; i < 7; i++)
  108.             Print(ESC "*b2W%c%c", 0x80, 0x00);  // Top border
  109.          }
  110.  
  111.       // Print the left border
  112.       Print(ESC "*b2W%c%c", 0xff, 0xff);
  113.  
  114.       // Signify the end of the raster graphic image transfer
  115.       Print(ESC "*rB");
  116.       }
  117.  
  118.    // Print the bottom border
  119.    Print(ESC "*p%dx%dY", RIGHTX, BOTTOMY);
  120.    Print(ESC "*r1A");
  121.    for (i = 0; i < 8 * NUMCOLS + 1; i++)
  122.       Print(ESC "*b2W%c%c", 0x80, 0x00);
  123.    Print(ESC "*rB");
  124.  
  125.    // Use the correct symbol set
  126.    Print(ESC "(%dU", sevenpt ? 0 : 8);
  127.  
  128.    // Set condensed print
  129.    Print(ESC "(s%sv16.66H", sevenpt ? "7" : "8.5");
  130.  
  131.    // Print the column numbers
  132.    for (column = 0; column < NUMCOLS; column++)
  133.       {
  134.       xpos = LEFTX + column * DOTSPERCOL + 7;
  135.       quotient  = (column + offset) / 10;
  136.       remainder = (column + offset) % 10;
  137.       Print(ESC "*p%dx%dY%d", xpos, TOPMARGIN - 10, remainder);
  138.       if (remainder == 0 && quotient > 0)
  139.          Print(ESC "*p%dx%dY%d", xpos, TOPMARGIN - adjust1, quotient);
  140.       }
  141.  
  142.    // Print the row numbers
  143.    for (row = 0; row < NUMROWS; row++)
  144.       Print(ESC "*p%dx%dY%2d", LEFTX - 45,
  145.          TOPMARGIN + row * DOTSPERROW + adjust2, row + offset);
  146.  
  147.    // Send a form feed and reset the printer
  148.    Print("\f" ESC "E");
  149.  
  150.    printf("\nDone!\n");
  151. }
  152.  
  153. void Print(char *output, ...)
  154. {
  155.    va_list argptr;
  156.    va_start(argptr, output);
  157.    vfprintf(stdprn, output, argptr);
  158.    va_end(argptr);
  159. }
  160.